<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>home.js</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        
        <h1>
            home.js
        </h1>
        <ul class="files">
            
            <li>
                app/assets/javascripts/home.js
                
            </li>
            <li>Last modified: 2017-02-03 18:43:29 +0800</li>
        </ul>
    </div>

    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>//= require echarts.min</p>

<p>var HOME_OBJ = {</p>

<pre><code>EChart: echarts.init(document.getElementById(&#39;main-chart&#39;)),
START_TIME: getDateBeforeSeveralDays(getDateToday(),29),
DATE_ARR: [],
ROOM_NUM_ARR:   new Array(30),
DINNER_NUM_ARR: new Array(30),
OPTION: {}</code></pre>

<p>}</p>

<p>HOME_OBJ.getEChart = function () {</p>

<pre><code>HOME_OBJ.getDateArray()                     // 获取30天时间(X轴)
HOME_OBJ.getRoomNums()                      // 获取房型订单数据
HOME_OBJ.OPTION = HOME_OBJ.option           // 获取图表参数
HOME_OBJ.EChart.setOption(HOME_OBJ.OPTION)  // 使用指定的配置项和数据显示图表</code></pre>

<p>}</p>

<p>jQuery(function ($) {</p>

<pre><code>if (getPageName() == &quot;HOME-MAIN-PAGE&quot;) {
    HOME_OBJ.getEChart()    // 渲染曲线
    // HOME_OBJ.getSmsSurplusNumber()              //短信剩余数量
}</code></pre>

<p>})</p>

<p>// 获取30天时间(X轴) HOME_OBJ.getDateArray = function() {</p>

<pre><code>for (var i = 0; i &lt; 30; i++) {
    HOME_OBJ.DATE_ARR[i] = getDateAfterSeveralDays(HOME_OBJ.START_TIME,i).substring(5,10)
}
return HOME_OBJ.DATE_ARR</code></pre>

<p>}</p>

<p>// 获取订单数据 HOME_OBJ.getRoomNums = function () {</p>

<pre><code>for (var i = 0; i &lt; 30; i++) {
    HOME_OBJ.ROOM_NUM_ARR[i] = 0
}
$.ajax({
    url: &quot;/api/store_orders/data&quot;,
    type: &quot;get&quot;,
    dataType: &#39;json&#39;,
    async: false,
    success: function(data) {
        var length = data.store_orders.length
        if (length &gt; 0) {
            var creat_times = []
            var nums = []
            creat_times.push(data.store_orders[0].substring(5,10))
            for (var i = 1; i &lt; length; i++) {
                var time_before = data.store_orders[i-1].substring(5,10)
                var time_after = data.store_orders[i].substring(5,10)
                if (time_before != time_after) {
                    creat_times.push(data.store_orders[i].substring(5,10))
                }
            }
            for (var i = 0; i &lt; creat_times.length; i++) {
                var n = 1
                for (var j = 0; j &lt; length; j++) {
                    if (creat_times[i] == data.store_orders[j].substring(5,10)) {
                        nums[i] = n++
                    }
                }
            }
            for (var i = 0; i &lt; creat_times.length; i++) {
                HOME_OBJ.ROOM_NUM_ARR[HOME_OBJ.getDateArray().indexOf(creat_times[i])] = nums[i]
            }
        } else {
            return false
        }
    },
    error: function() {
        commonEvents.popupView(&quot;提 醒&quot;, &quot;获取订单数据失败&quot;, &quot;确 定&quot;)
    }
})</code></pre>

<p>}</p>

<p>// 获取图表参数 HOME_OBJ.option = {</p>

<pre><code>title: {
    text: &#39;&#39;
},
tooltip: {
    trigger: &#39;axis&#39;
},
legend: {
    data:[&#39;订单&#39;]
},
grid: {
    left: &#39;3%&#39;,
    right: &#39;4%&#39;,
    bottom: &#39;3%&#39;,
    containLabel: true
},
toolbox: {
    feature: {
        saveAsImage: {}
    }
},
xAxis: {
    type: &#39;category&#39;,
    boundaryGap: false,
    data: HOME_OBJ.getDateArray()
},
yAxis: {
    type: &#39;value&#39;
},
series: [ // 加载顺序
    {
        name:&#39;订单&#39;,
        type:&#39;line&#39;,
        stack: &#39;总量&#39;,
        data: HOME_OBJ.ROOM_NUM_ARR
    }
]</code></pre>

<p>}</p>

    </div>
  


  


  
  


  


  

  



  

    

    

    


    


    <!-- Methods -->
              </div>

    </div>
  </body>
</html>
